<?php

namespace App\Providers;

use Auth;
use Illuminate\Auth\EloquentUserProvider;
use Illuminate\Contracts\Auth\Authenticatable as UserContract;

class CustomUserProvider extends EloquentUserProvider{
    public function __construct($hasher, $model){
        parent::__construct($hasher, $model);
    }
    /**
     * Validate a user against the given credentials.
     * @param  \Illuminate\Contracts\Auth\Authenticatable $user
     * @param  array $credentials
     * @return bool
     */
    //特殊密码加密需求 后面去掉_bak
    public function validateCredentials_bak(UserContract $user, array $credentials){
        $pwd_hash = $user->pwd_hash;
        $plain = $credentials['password'];
        $QS_pwdhash = "2fmf@Gx9RN3ncqvm";
        $pwd = md5(md5($plain) . $pwd_hash . $QS_pwdhash);
        if($pwd == $user->getAuthPassword()){
            $user->password = $this->hasher->make($plain);
            $user->save();
            return true;
        }else{
            $plain = $credentials['password'];
            return $this->hasher->check($plain, $user->getAuthPassword());
        }
    }

    /**
     * Bootstrap the application services.
     *
     * @return void
     */
    public function boot(){
        //
    }

    /**
     * Register the application services.
     *
     * @return void
     */
    public function register(){
        //
    }
}
